package com.example.utils;


import com.example.service.DriverChecks;
import com.example.vo.UserVO;
import org.hibernate.validator.HibernateValidator;
import org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator;
import org.hibernate.validator.resourceloading.PlatformResourceBundleLocator;

import java.util.*;

import javax.validation.ConstraintViolation;
import javax.validation.GroupSequence;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.groups.Default;
public class ValidatorUtil {

    private static Validator validator = Validation.byProvider(HibernateValidator.class)
            .configure().messageInterpolator(new ResourceBundleMessageInterpolator(new PlatformResourceBundleLocator("valid")))
            .buildValidatorFactory()
            .getValidator();



    public static <T> Map<String,StringBuffer> validateHandle(T obj){
        Map<String,StringBuffer> errorMap = null;
        Set<ConstraintViolation<T>> set = validator.validate(obj,Default.class, DriverChecks.class);
        if(set != null && set.size() >0 ){
            errorMap = new HashMap<String,StringBuffer>();
            String property = null;
            for(ConstraintViolation<T> cv : set){
                //这里循环获取错误信息，可以自定义格式
                property = cv.getPropertyPath().toString();
                if(errorMap.get(property) != null){
                    errorMap.get(property).append("," + cv.getMessage());
                }else{
                    StringBuffer sb = new StringBuffer();
                    sb.append(cv.getMessage());
                    errorMap.put(property, sb);
                }
            }
        }
        return errorMap;
    }

    public static void main(String[] args) {
<<<<<<< Updated upstream
        System.out.println(new Integer(1) +1);
=======
      List<Integer> list = new ArrayList<>();

        list.add(21);
        list.add(22);
        list.add(23);
        list.add(24);
        list.add(25);
        list.add(26);
        list.add(27);
        list.add(28);
        list.add(29);
        int i = 0;
        while(i < 9){
           int ma =i+5;
           if(ma >= list.size()){
               List<Integer> sub =  list.subList(i,list.size());
               System.out.println(Collections.max(sub));
               System.out.println(Collections.min(sub));
               break;
           }
            List<Integer> sub =  list.subList(i,ma);
            System.out.println(Collections.max(sub));
            System.out.println(Collections.min(sub));
            i=i+5;
        }



>>>>>>> Stashed changes
    }


}
